import fs from 'fs';

const {exec} = require('child_process');

async function getBatteryReport() {
    const command = 'chcp 65001 && Powercfg/batteryreport';

    return new Promise((resolve, reject) => {
        exec(command, (error: any, stdout: string, stderr: string) => {
            if (error) {
                console.error(`错误: ${error.message}`);
                return null;
            }
            if (stderr) {
                console.error(`stderr: ${stderr}`);
                return null;
            }

            const result = stdout.split('\n');
            const pathLine = result[1].trim();
            const path = pathLine.substring(17, pathLine.length - 1);

            resolve(fs.readFileSync(path, 'utf8'));
        });
    });
}


export default getBatteryReport;